import 'package:flutter/material.dart';

class ColorProvider extends ChangeNotifier {
  // 预定义的颜色列表
  final List<Color> predefinedColors = [
    Color(0xFFFFF5E6), // 暖白光（默认）
    Color(0xFFF5F5F5), // 自然白光
    Color(0xFFFFE4E1), // 柔和暖光
    Color(0xFFF0FFFF), // 清新冷光
    Color(0xFFFFFAF0), // 日光色
    Color(0xFFF8F8FF), // 月光色
  ];

  // 当前颜色的HSB值
  double _hue = 0.0;
  double _saturation = 0.0;
  double _brightness = 1.0;

  ColorProvider() {
    // 使用第一个预设颜色（暖白光）作为初始颜色
    setColor(predefinedColors[0]);
  }

  // 获取当前颜色
  Color get currentColor {
    return HSVColor.fromAHSV(1.0, _hue, _saturation, _brightness).toColor();
  }

  // 设置预定义颜色
  void setColor(Color color) {
    final HSVColor hsvColor = HSVColor.fromColor(color);
    setHSB(
      hue: hsvColor.hue,
      saturation: hsvColor.saturation,
      brightness: hsvColor.value,
    );
  }

  // 设置HSB值
  void setHSB({double? hue, double? saturation, double? brightness}) {
    if (hue != null) _hue = hue;
    if (saturation != null) _saturation = saturation;
    if (brightness != null) _brightness = brightness;
    notifyListeners();
  }

  // 重置颜色
  void reset() {
    _hue = 0.0;
    _saturation = 0.0;
    _brightness = 1.0;
    notifyListeners();
  }
}
